package rita.ui.component;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

import rita.settings.Language;
import rita.ui.component.DialogSelectEnemies.RobotTemp;

public class DialogPositionRobot extends CloseableJDialog {
	
	private JTextField xCoord = new JTextField("0");
	private JTextField yCoord = new JTextField("0");
	private JPanel panelXY = new JPanel();
	private JPanel panelButtons = new JPanel();
	private JButton okButton = new JButton(Language.get("ok"));
	private JButton cancelButton = new JButton(Language.get("cancel"));
	RobotTemp robotTemp;
	public DialogPositionRobot(RobotTemp robotTemp) {
		//super(parent, Language.get("robot.position"),true);
		initialize(robotTemp);
	}
	
	private void initialize(RobotTemp robotTemp){
		this.robotTemp=robotTemp;
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		okButton.addActionListener(new OkAction());
		cancelButton.addActionListener(new CancelAction());
		this.setTitle(Language.get("positionOf")+" "+robotTemp.getRobotName());
		this.getContentPane().setLayout(new BorderLayout(6, 6));
		this.add(panelXY,BorderLayout.CENTER);
		this.add(panelButtons,BorderLayout.SOUTH);
		xCoord.setText(String.valueOf(robotTemp.getX()));
		yCoord.setText(String.valueOf(robotTemp.getY()));
		panelXY.add(xCoord);
		panelXY.add(yCoord);
		panelButtons.add(okButton);
		panelButtons.add(cancelButton);
		PositionCalc.centerDialog(this);
		this.pack();
		this.setVisible(true);
	}
	
	private class CancelAction implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			closeDialog();
		}
		
		
	}

	private class OkAction implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			robotTemp.setX(Integer.parseInt(xCoord.getText()));
			robotTemp.setY(Integer.parseInt(yCoord.getText()));
			closeDialog();
		}
		
		
	}
}
